package User

import (
	"FromNowOnPromote/博客系统/Tblog/models"
	"FromNowOnPromote/博客系统/Tblog/models/Blog"
	"log"
	"time"
)

type TbUser struct {
	//gorm.Model
	Uuid         int       `gorm:"AUTO_INCREMENT;PRIMARY_KEY"`      //用户uuid
	Username     string    `gorm:"type:varchar(255);not null"`      //用户名
	Password     string    `gorm:"type:varchar(255);not null"`      //密码
	Sex          string    `gorm:"type:varchar(255);"`              //性别
	Introduction string    `gorm:"type:text"`                       //个人简介
	Email        string    `gorm:"type:varchar(255)"`               //邮箱
	Birthday     time.Time `gorm:"type:date"`                       //出生日期
	Address      string    `gorm:"type:varchar(255)"`               //住址
	IconUrl      string    `gorm:"type:varchar(255);"`              //用户头像
	User_locked  int       `gorm:"type:int(20);not null;default:1"` //用户状态，默认为1

	//外键关联
	TBloginfo []Blog.TBloginfo `gorm:"FOREIGNKEY:UId;ASSOCIATION_FOREIGNKEY:Uuid"`
}

//设置表名
func (TbUser) TableName() string {
	return "tbuser"
}

func init() {
	db := models.ConnDb()
	//判断表是否存在
	bl := db.HasTable(&TbUser{})
	if bl == false {
		db.CreateTable(&TbUser{})
	} else {
		err := db.AutoMigrate(&TbUser{}).Error
		if err != nil {
			log.Fatal(err)
		}
	}
}
